package com.jsgt.greekfire.ui.coin

import android.widget.TextView
import androidx.viewpager.widget.ViewPager
import com.fhx.core.base.BaseActivity
import com.fhx.core.base.BaseFragment
import com.google.android.material.tabs.TabLayout
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.trading.adapter.PagerAdapter
import kotlinx.android.synthetic.main.activity_coins_order.*

class CoinsOrderActivity : BaseActivity() {
    private val fragments: MutableList<BaseFragment> = ArrayList()
    private var coinFragment: CoinsOrderFragment? = null
    var tvTitle: TextView? = null
    override fun getLayoutId(): Int = R.layout.activity_coins_order
    override fun main() {
        initTab()
        tvTitle = findViewById(R.id.title_tv)
        tvTitle?.text =resources.getString(R.string.coins_order_title)
    }

    private fun initTab() {
        var item = resources.getStringArray(R.array.coins_order_tab_list)
        val tabs = java.util.ArrayList<String>()
        for (i in item.indices) {
            tabs.add(item[i])
            coinFragment = CoinsOrderFragment.newInstance(item[i])
            fragments.add(coinFragment!!)
        }

        tabCoinsOrder.tabMode = TabLayout.MODE_FIXED
        tabCoinsOrder.setupWithViewPager(vpCoinsOrder)
        vpCoinsOrder.adapter = PagerAdapter(
            supportFragmentManager,
            fragments,
            tabs
        )
        vpCoinsOrder.currentItem = 0
        vpCoinsOrder.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
            }
        })
    }
}